package cn.itheima.student.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.itheima.student.daomain.Student;
import cn.itheima.student.service.StudentService;
import cn.itheima.student.service.impl.StudentServiceImpl;


public class StudentFindAllByIdServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html");
		
		String id = request.getParameter("sid");
		if (id!=null&&id!="") {
			int id2 = Integer.parseInt(id);
			StudentService service = new StudentServiceImpl();
			List<Student> list= service.findStudentById(id2);
			
			request.setAttribute("st", list);
			request.getRequestDispatcher("/student/find.jsp").forward(request, response);;
		}
		else {
			PrintWriter out = response.getWriter();
			out.print("<script language='javascript'>alert('输入有误！请重新输入');window.location.href='/student/studentfindbyId.jsp';</script>");

		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
